package com.ruoyi.award.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.firefighter.domain.FirefighterInfo;
import com.ruoyi.firefighter.service.IFirefighterInfoService;
import com.sun.org.apache.bcel.internal.generic.NEW;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.award.mapper.FirefighterAwardMapper;
import com.ruoyi.award.domain.FirefighterAward;
import com.ruoyi.award.service.IFirefighterAwardService;

/**
 * 奖励情况Service业务层处理
 *
 * @author ruoyi
 * @date 2024-10-11
 */
@Service
public class FirefighterAwardServiceImpl implements IFirefighterAwardService
{
    @Autowired
    private FirefighterAwardMapper firefighterAwardMapper;
    @Autowired
    private IFirefighterInfoService iFirefighterInfoService;
    /**
     * 查询奖励情况
     *
     * @param id 奖励情况主键
     * @return 奖励情况
     */
    @Override
    public FirefighterAward selectFirefighterAwardById(Long id)
    {
        return firefighterAwardMapper.selectFirefighterAwardById(id);
    }

    /**
     * 查询奖励情况列表
     *
     * @param firefighterAward 奖励情况
     * @return 奖励情况
     */
    @Override
    public List<FirefighterAward> selectFirefighterAwardList(FirefighterAward firefighterAward)
    {
        return firefighterAwardMapper.selectFirefighterAwardList(firefighterAward);
    }

    /**
     * 新增奖励情况
     *
     * @param firefighterAward 奖励情况
     * @return 结果
     */
    @Override
    public int insertFirefighterAward(FirefighterAward firefighterAward)
    {
        firefighterAward.setCreateTime(DateUtils.getNowDate());
        FirefighterInfo firefighterInfo1 = new FirefighterInfo();
        firefighterInfo1.setIdCardNumber(firefighterAward.getFirefighterIdCard());
        FirefighterInfo firefighterInfo= iFirefighterInfoService.selectFirefighterInfoBySfz(firefighterInfo1);
        if (firefighterInfo==null){
            return 0;
        }
        firefighterAward.setFirefighterId(firefighterInfo.getUserId());
        return firefighterAwardMapper.insertFirefighterAward(firefighterAward);
    }

    /**
     * 修改奖励情况
     *
     * @param firefighterAward 奖励情况
     * @return 结果
     */
    @Override
    public int updateFirefighterAward(FirefighterAward firefighterAward)
    {
        firefighterAward.setUpdateTime(DateUtils.getNowDate());
        return firefighterAwardMapper.updateFirefighterAward(firefighterAward);
    }

    /**
     * 批量删除奖励情况
     *
     * @param ids 需要删除的奖励情况主键
     * @return 结果
     */
    @Override
    public int deleteFirefighterAwardByIds(Long[] ids)
    {
        return firefighterAwardMapper.deleteFirefighterAwardByIds(ids);
    }

    /**
     * 删除奖励情况信息
     *
     * @param id 奖励情况主键
     * @return 结果
     */
    @Override
    public int deleteFirefighterAwardById(Long id)
    {
        return firefighterAwardMapper.deleteFirefighterAwardById(id);
    }

    @Override
    public void deleteFirefighterAwardById1(Long userId) {
         firefighterAwardMapper.deleteFirefighterAwardByIduser(userId);
    }
}
